package com.young.shop.service.impl;

import com.young.shop.dao.impl.OrdersListDaoImpl;
import com.young.shop.pojo.entity.OrderList;
import com.young.shop.pojo.entity.OrdersDetails;
import com.young.shop.pojo.entity.User;
import com.young.shop.service.OrderService;

import java.sql.SQLException;
import java.util.List;

public class OrderServiceImpl implements OrderService {
    OrdersListDaoImpl ordersListDao = new OrdersListDaoImpl();
    @Override
    public List queryByUserId(Long userId) {
//        User queryUser = ordersListDao.selectByUserName(userName);
//        long id = queryUser.getId();
        List<OrderList> orderLists = ordersListDao.selectById(userId);
        if (orderLists.toString() == null) {
            throw new RuntimeException("用户订单列查询表失败或者订单列表为空");
        }
        return orderLists;
    }


    //判断状态值--根据状态
    @Override
    public List<OrderList> OrderByZtList(int status,Long userId) {
        if (status == 1) {
            List<OrderList> orderLists = ordersListDao.selectByZtId(status, userId);
            return orderLists;
        } else if (status == 2) {
            List<OrderList> orderLists = ordersListDao.selectByZtId(status, userId);
            return orderLists;
        } else if (status == 3) {
            List<OrderList> orderLists = ordersListDao.selectByZtId(status, userId);
            return orderLists;
        } else if (status == 4) {
            List<OrderList> orderLists = ordersListDao.selectByZtId(status, userId);
            return orderLists;
        } else {
            throw new RuntimeException("用户订单查询失败或者订单列表为空");
        }
    }

    @Override
    public int stateChangeService(int id, int status){
        int newStatus;
        if (status == 1 || status == 3){
            newStatus = status + 1;
        }else {
            newStatus = status;
//            System.out.println(newStatus + "status");
        }
        int i = ordersListDao.byIdAlterstaStatus(id, newStatus);
        if (i == 1){
            return i;
        }else {
            throw new RuntimeException("申请修改订单状态失败");
        }
    }

    @Override
    public List<OrdersDetails> detailsById(Long id) {
        List<OrdersDetails> ordersDetails = ordersListDao.orderdetailByOrderId(id);
        if (ordersDetails.toString() == null){
            throw new RuntimeException("订单详情查询失败");
        }
        return ordersDetails;
    }

}
